package cn.ren.hai.core.entity;

import cn.ren.hai.core.json.LongJsonDeserializer;
import cn.ren.hai.core.json.LongJsonSerializer;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author 57556
 */
@Getter
@Setter
public class BaseEntity implements Serializable {

    @ApiModelProperty(value = "主键id")
    @TableId(type = IdType.ASSIGN_ID)
    @JsonDeserialize(using = LongJsonDeserializer.class)
    @JsonSerialize(using = LongJsonSerializer.class)
    private Long id;

    @ApiModelProperty(value = "乐观锁")
    @TableField("revision")
    @Version
    private Integer revision;

    @ApiModelProperty(value = "删除状态")
    @TableLogic
    @TableField(fill = FieldFill.INSERT)
    private String del;

    @ApiModelProperty(value = "状态")
    @TableField(fill = FieldFill.INSERT,value = "status")
    private Integer status;

    @ApiModelProperty(value = "创建人")
    @TableField(value = "created_id",fill = FieldFill.INSERT)
    private Long createdId;

    @ApiModelProperty(value = "创建人姓名")
    @TableField(value = "created_name",fill = FieldFill.INSERT)
    private String createdName;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "created_time",fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdTime;

    @ApiModelProperty(value = "更新人")
    @TableField(value = "updated_id",fill = FieldFill.UPDATE)
    private Long updatedId;

    @ApiModelProperty(value = "更新人姓名")
    @TableField(value = "updated_name",fill = FieldFill.UPDATE)
    private String updatedName;

    @ApiModelProperty(value = "更新时间")
    @TableField(value = "updated_time",fill = FieldFill.UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedTime;

    @ApiModelProperty(value = "排序")
    @TableField(value = "sort",fill = FieldFill.INSERT)
    private Integer sort;

    @ApiModelProperty(value = "编号")
    @TableField("code")
    private String code;

    @ApiModelProperty(value = "模块名称")
    @TableField("name")
    private String name;


}
